#include "./settings.h"

QSharedPointer<Settings> Settings::_instance;

Settings::Settings()
{
    /*this->login = "root";
    this->password = "";
    this->dbname = "emdp";
    this->hostname = "localhost";*/
}

QSharedPointer<Settings> Settings::instance()
{
    if(_instance.isNull())
    {
        _instance = QSharedPointer<Settings>(new Settings);
    }
    return _instance;
}

QSettings::Status Settings::save()
{
    QSettings settings;
    settings.beginGroup("Database settings");
    settings.setValue("login", this->login);
    settings.setValue("password", this->password);
    settings.setValue("dbname", this->dbname);
    settings.setValue("hostname", this->hostname);
    settings.endGroup();
    return settings.status();
}

QSettings::Status Settings::load()
{
    QSettings settings;    
    settings.beginGroup("Database settings");
    this->login = settings.value("login").toString();
    this->password = settings.value("password").toString();
    this->dbname = settings.value("dbname").toString();
    this->hostname = settings.value("hostname").toString();
    settings.endGroup();
    return settings.status();
}

bool Settings::isEmpty()
{
    if(this->hostname.compare("") == 0)
    {
        return true;
    }
    return false;
}
